package com.ruanyun.modular.admin.mapper;

import com.ruanyun.modular.admin.entity.TExhaustEquipment;
import com.ruanyun.modular.admin.entity.TExhaustOutlet;
import com.ruanyun.modular.admin.model.params.TExhaustOutletParam;
import com.ruanyun.modular.admin.model.result.PollutantsResult;
import com.ruanyun.modular.admin.model.result.TExhaustEquipmentResult;
import com.ruanyun.modular.admin.model.result.TExhaustOutletResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 废气排放口 Mapper 接口
 * </p>
 *
 * @author zs
 * @since 2021-04-17
 */
@Repository
public interface TExhaustOutletMapper extends BaseMapper<TExhaustOutlet> {

    /**
     * 获取列表
     *
     * @author zs
     * @Date 2021-04-17
     */
    List<TExhaustOutletResult> customList(@Param("paramCondition") TExhaustOutletParam paramCondition);

    /**
     * 获取map列表
     *
     * @author zs
     * @Date 2021-04-17
     */
    List<Map<String, Object>> customMapList(@Param("paramCondition") TExhaustOutletParam paramCondition);

    /**
     * 获取分页实体列表
     *
     * @author zs
     * @Date 2021-04-17
     */
    Page<TExhaustOutletResult> customPageList(@Param("page") Page page, @Param("paramCondition") TExhaustOutletParam paramCondition);

    /**
     * 获取分页map列表
     *
     * @author zs
     * @Date 2021-04-17
     */
    Page<Map<String, Object>> customPageMapList(@Param("page") Page page, @Param("paramCondition") TExhaustOutletParam paramCondition);

    Page<TExhaustOutletResult> customPageList1(@Param("page") Page page, @Param("paramCondition") TExhaustOutletParam paramCondition);


    /*根据companyId 查询是否存在数据*/
    @Select("SELECT * FROM t_exhaust_outlet WHERE company_id = #{companyId}  and del_flag != 2 ")
    List<TExhaustOutlet> getDetails(@Param("companyId")Long companyId);


    /*获取污染物信息*/
     @Select("SELECT\n" +
             "\tGROUP_CONCAT(p.emission_limit) AS emissionLimits,\n" +
             "\tGROUP_CONCAT(s.`name`) AS pollutantsType,\n" +
             "   GROUP_CONCAT(p.emission_standards) as emissionStandards,\n" +
             "GROUP_CONCAT(s.description) as pollutantsName\n" +
             "FROM\n" +
             "\tpollutants_info p\n" +
             "LEFT JOIN sys_dict s ON p.pollutants_type = s.dict_id\n" +
             "WHERE\n" +
             "\tp.exhaust_id = #{id} AND p.del_flag != 2  ")
    PollutantsResult getPolluTantsInfo(@Param("id")Integer id);

     /*根据污染物id 获取companyId*/
    @Select("SELECT * from t_exhaust_outlet WHERE id = (SELECT exhaust_id from pollutants_info WHERE id = #{pid} and del_flag != 2) AND del_flag != 2")
    TExhaustOutletResult getCidByPid(@Param("pid") Integer pid);


    Page<TExhaustOutletResult> getExhaustPage(@Param("pageContext") Page pageContext, @Param("companyId") Integer companyId);


}
